<?php
class pinglunAction extends Action
{
	function add()
	{
		$uid=$_COOKIE["uchome_uid"];
		$uchome_auth=$_COOKIE["uchome_auth"];
		if(!$uchome_auth) die("会员没有登陆");
		
		$content=$_REQUEST["yingxiangcontent"];//应像内容
		$tid=$_REQUEST["tid"];//线路的id
		$mr=M("pinglun");
		
		//获取这个用户的最大数，如果没有达到最大数就添加
		global $SYS_config;
		$rs=$mr->query("select count(*) as ynum from ".DQ."pinglun where pinglun3=580 and pinglun2=$tid and pinglun4=$uid");
		if($rs["ynum"]>$SYS_config["addYingx"]) die("您已经添加到最大条数了");
		
		
		$data["pinglun3"]=580;
		$data["pinglun1"]=$content;
		$data["pinglun2"]=$tid;
		$data["pinglun8"]=time();
		$data["pinglun4"]=$uid;
		$rs=$mr->data($data)->add();
		echo ($rs)?"添加成功":"添加失败";
		
		
	}
	
	
	function getrslist($sql)
	{
		$mr=M("pinglun");
		$rs=$mr->where($sql)->select();
		return $rs?$rs:null;
	}
	
	/**
	 * 获取某一条线路的好评率,返回样式:98%
	 * @param $tid  线路id
	 */
	function gettourhaopinglv($tid)
	{
		if(!is_numeric($tid)) die("线路id必须为数字");
		$mr=M("pinlun");
		$rs=$mr->query("select avg(pinglun9+pinglun10+pinglun11+pinglun12+pinglun13+pinglun14) as onetotal from ".DQ."pinglun where pinglun2=$tid and pinglun3=579");
		$n=0;
		$i=0;
		
		foreach($rs as $v)
		{
			$n+=$v["onetotal"];
			$i+=1;
		}
		return number_format(($n*100)/($i*30),0,".","") ."%";
	}
	
	/**
	 * 显示添加评论的主界面
	 */
	function addhtm()
	{
		$orderno=$_REQUEST["orderno"];
		if(!preg_match("/^[a-zA-Z][\d]+$/", $orderno)) die("订单号不正确，请从正确的地址进入");
		$public=A("public");
		//查询订单和线路信息
		$sql="select * from ".DQ."orderform a left join ".DQ."tour b on a.orderform1=b.tour0 where a.orderform3='".$orderno."'";
		
		$rs=$public->query($sql);
		$this->assign("rs",$rs[0]);
		$this->display();
	}
	
	/**
	 * 保存添加评论数据
	 */
	function addsave()
	{
		
		$yzm=$_REQUEST["yzm"];//获取验证码
		if($yzm!=$_SESSION['SafeCode']){
			alert("",1,"验证码不正确，请认真填写");
			die();
		}
		
		$myp=D("pinglun");
		$myp->create() ;
		$res=$myp->add();
		$t= ($res>0)?"评论提交成功":"评论提交失败";
		alert("/",2,"$t");
		
		
	}

	

	
	
	
}

?>